home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / SanFrancisco_1989 / SF-Devcon89.2 / Workbench / AppIcon / appicon.c next >
Encoding:
C/C++ Source or Header  |  1992-08-27  |  3.5 KB  |  147 lines

  1. /*
  2.     Code to test AppIcon feature of Workbench.
  3. */
  4.  
  5. #include <intuition/intuition.h>
  6. #include <exec/memory.h>
  7. #include <workbench/startup.h>
  8. #include "workbench/workbench.h"
  9.  
  10. #include "appicon.image"
  11.  
  12. #define INTUITIONNAME    "intuition.library"
  13. #define WORKBENCHNAME    "workbench.library"
  14. #define ICONNAME    "icon.library"
  15.  
  16. struct IntuitionBase *IntuitionBase = NULL;
  17. struct WorkbenchBase *WorkbenchBase = NULL;
  18. struct IconBase *IconBase = NULL;
  19.  
  20. struct NewWindow nw = {
  21.     0, 0,        /* leftedge, topedge */
  22.     160,50,        /* width, height */
  23.     -1, -1,        /* DetailPen, BlockPen */
  24.     CLOSEWINDOW,        /* IDCMP flags */
  25.     WINDOWCLOSE|WINDOWDRAG,        /* flags */
  26.     NULL,        /* FirstGadget */
  27.     NULL,        /* Image */
  28.     "AppIcon",    /* Title */
  29.     NULL,        /* Screen */
  30.     NULL,        /* BitMap */
  31.     0, 0,        /* MinWidth, MinHeight */
  32.     0, 0,        /* MaxWidth, MaxHeight */
  33.     WBENCHSCREEN    /* type */
  34. };
  35.  
  36. main(argc, argv)
  37. int argc;
  38. char **argv;
  39. {
  40.     void *OpenLibrary();
  41.     struct MsgPort *CreatePort();
  42.     struct Window *OpenWindow();
  43.     struct IntuiMessage *GetMsg();
  44.     struct AppIcon *AddAppIcon();
  45.     struct DiskObject *GetDiskObject();
  46.  
  47.     struct MsgPort *msgport = NULL;
  48.     struct Window *win = NULL;
  49.     struct AppIcon *ai = NULL;
  50.     struct IntuiMessage *imsg;
  51.     struct AppMessage *amsg;
  52.     struct WBArg *argptr;
  53.     struct DiskObject *dobj;
  54.     ULONG id = 1, userdata = 0;
  55.     BOOL done = FALSE;
  56.     int i, imagememsize = 0;
  57.  
  58.     printf("ai: enter\n");
  59.     if (!(IntuitionBase = OpenLibrary(INTUITIONNAME, 0))) {
  60.         printf("ai: could not open intuition\n");
  61.         goto err;
  62.     }
  63.     if (!(WorkbenchBase = OpenLibrary(WORKBENCHNAME, 36))) {
  64.         printf("ai: could not open workbench\n");
  65.         goto err;
  66.     }
  67.     if (!(IconBase = OpenLibrary(ICONNAME, 36))) {
  68.         printf("ai: could not open icon\n");
  69.         goto err;
  70.     }
  71.     if (!(msgport = CreatePort("appicon", 0))) {
  72.         printf("ai: could not createport\n");
  73.         goto err;
  74.     }
  75.     if (!(win = OpenWindow(&nw))) {
  76.         printf("ai: could not openwindow\n");
  77.         goto err;
  78.     }
  79.     if (!(dobj = GetDiskObject(NULL))) {
  80.         printf("ai: could not getdiskobject(NULL)\n");
  81.         goto err;
  82.     }
  83.     dobj->do_Gadget.Width = image1.Width;
  84.     dobj->do_Gadget.Height = image1.Height;
  85.     dobj->do_Gadget.GadgetRender = &image1;
  86.     imagememsize = (image1.Width * image1.Height * image1.Depth) / 8;
  87.     if (!(image1.ImageData = (USHORT *)AllocMem(imagememsize, MEMF_CHIP))) {
  88.         printf("ai: could not get chip mem for image\n");
  89.         goto err;
  90.     }
  91.     CopyMem(imageData1, image1.ImageData, imagememsize);
  92.     printf("ai: calling AddAppIcon...");
  93.     if (!(ai = AddAppIcon(id, userdata, "AppIcon", msgport, NULL, dobj))) {
  94.         printf("ai: could not addappicon\n");
  95.         goto err;
  96.     }
  97.     printf("ai: ok, ai = %lx, going to sleep\n", ai);
  98.     do {
  99.         Wait((1 << win->UserPort->mp_SigBit) |
  100.             (1 << msgport->mp_SigBit));
  101.         while (imsg = GetMsg(win->UserPort)) {
  102.             if (imsg->Class == CLOSEWINDOW) {
  103.                 done = TRUE;
  104.             }
  105.         };
  106.         while (amsg = GetMsg(msgport)) {
  107.             printf("ai: appmsg=%lx, Type=%ld, ID=%ld, UserData=%ld, NumArgs=%ld\n", amsg, amsg->am_Type, amsg->am_ID, amsg->am_UserData, amsg->am_NumArgs);
  108.             argptr = amsg->am_ArgList;
  109.             for (i=0; i<amsg->am_NumArgs; i++) {
  110.                 printf("\targ(%ld): Name='%s', Lock=%lx\n",
  111.                     i, argptr->wa_Name, argptr->wa_Lock);
  112.                 argptr++;
  113.             }
  114.             ReplyMsg(amsg);
  115.         };
  116.     } while (!done);
  117.  
  118.     if (ai) {
  119.         printf("ai: calling RemoveAppIcon\n");
  120.         RemoveAppIcon(ai);
  121.     }
  122.  
  123. err:
  124.     if (win) {
  125.         CloseWindow(win);
  126.     }
  127.     if (msgport) {
  128.         DeletePort(msgport);
  129.     }
  130.     if (dobj) {
  131.         if (imagememsize) {
  132.             FreeMem(image1.ImageData, imagememsize);
  133.         }
  134.         FreeDiskObject(dobj);
  135.     }
  136.     if (IconBase) {
  137.         CloseLibrary(IconBase);
  138.     }
  139.     if (WorkbenchBase) {
  140.         CloseLibrary(WorkbenchBase);
  141.     }
  142.     if (IntuitionBase) {
  143.         CloseLibrary(IntuitionBase);
  144.     }
  145.     printf("ai: exit\n");
  146. }
  147.